<?php
header('content-type: text/html;charset=utf-8;');
function cart()
{
    //拿到登录用户名
    $uname = $_POST['username'];

    $link = mysqli_connect('127.0.0.1', 'root', 'root', 'demo1');
    //查询
    $sql = "SELECT * FROM `shop` WHERE `username`='$uname'";

    $res = mysqli_query($link, $sql);

    $data = mysqli_fetch_all($res, MYSQLI_ASSOC); 

    //把查找的数据返回前端
    print_r(json_encode($data));
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    cart();
}